package api

import (
	"github.com/gogf/gf/errors/gerror"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/util/gvalid"
	"shrimp-blog-server/app/model"
	"shrimp-blog-server/utils"
)

func (*apiSorts) Get(request *ghttp.Request) {
	sortService.GetSorts(request, getQueryParamID(request)...)
}

func (*apiSorts) Post(request *ghttp.Request) {
	var sorts []model.SortsRequest
	_ = request.Parse(&sorts)
	if e := gvalid.CheckStructWithData(request.Context(), model.SortsRequest{}, sorts, nil); e != nil {
		g.Log().Info(gerror.Current(e))
		utils.Response.ErrorResponseExit(request, gerror.Current(e).Error())
	}
	sortService.AddSorts(request, sorts...)
}

func (*apiSorts) Put(request *ghttp.Request) {
	var sorts []model.SortsRequest
	_ = request.Parse(&sorts)
	if e := gvalid.CheckStructWithData(request.Context(), model.SortsRequest{}, sorts, nil); e != nil {
		g.Log().Info(gerror.Current(e))
		utils.Response.ErrorResponseExit(request, gerror.Current(e).Error())
	}
	sortService.UpdateSorts(request, sorts...)
}

func (*apiSorts) Delete(request *ghttp.Request) {
	sortService.DeleteSorts(request, getQueryParamID(request)...)
}
func (*apiSorts) GetListPage(request *ghttp.Request) {
	sortService.GetSortsPage(request, getPage(request))
}
